// pages/today-shopping/shopping.js
import {
  ajax,
  src,
  util
} from "../../utils/util.js";
Page({

  /**
   * 页面的初始数据
   */
  data: {
    vertical: false,
    autoplay: true,
    circular: true,
    interval: 2000,
    duration: 500,
    banners:'',
    shoplist:'',
  },
  // 今日拼购搜索跳转
  todayShopSearch:function() {
    wx.navigateTo({
      url: '/pages/today-shopping-search/search',
    })
  },
  // 今日拼购商品详情
  togrouppurchasecommodity: function (e) {
    let ptid = e.currentTarget.dataset.ptid;
    wx.navigateTo({
      url: '/pages/group-purchase-commodity/commodity?ptid=' + ptid,
    })
  },
  //获取轮播图
  getbanner: function () {
    ajax('/api/Diagram/Get?requestContent=' + JSON.stringify({
      token: wx.getStorageSync('Access_token'),
      Province: wx.getStorageSync('address_component').province,
      City: wx.getStorageSync('address_component').city,
      District: wx.getStorageSync('address_component').district,
      BroadCastType: 3
    }), {
        header: {
          'Accept': 'application/x-www-form-urlencoded', // 默认值
        },
        method: "get",
      }, res => {
        // console.log(res, 'banner')
        this.setData({
          banners: res.Models
        })
      })
  },
  //今日拼购商品
  getlist:function(){
    ajax('/api/Todayshopping/Get?requestContent=' + JSON.stringify({
      token: wx.getStorageSync('Access_token'),
      Title: "",
      PageIndex:0,
      Province: wx.getStorageSync('address_component').province,
      City: wx.getStorageSync('address_component').city,
      District: wx.getStorageSync('address_component').district
    }), {
        header: {
          'Accept': 'application/x-www-form-urlencoded', // 默认值
        },
        method: "get",
      }, res => {
        this.setData({
          shoplist: res.Models
        })
      })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getbanner()
    this.getlist()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})